package services

import (
	"github.com/labstack/gommon/log"
	"law_case_api/dto"
	"law_case_api/models"
)

// CreateCustomerContact 创建客户联系人信息
func (customer CustomerService) CreateCustomerContact(wzjCustomerContact models.WzjCustomerContact) (bool, error) {
	if err := db.Create(&wzjCustomerContact).Error; err != nil {
		log.Error("CreateCustomerContact--创建客户联系人信息失败,失败原因：", err)
		return false, err
	}
	return true, nil
}

// GetCustomerContactListByCustomerId 根据客户联系人信息列表
func (customer CustomerService) GetCustomerContactListByCustomerId(customerId int) ([]dto.CustomerContactResp, error) {
	var wzjCustomerContacts []dto.CustomerContactResp
	sql := `SELECT contact_id,customer_id,contact_name,contact_phone,create_user_id,create_date FROM wzj_db.wzj_customer_contact WHERE customer_id = ? order by create_date desc;`
	if err := db.Raw(sql, customerId).Find(&wzjCustomerContacts).Error; err != nil {
		log.Error("GetContractAccessoryListByContractId--查询失败,失败原因：", err)
		return wzjCustomerContacts, err
	}
	return wzjCustomerContacts, nil
}
